package org.flexthinker.binding.ui.form.binding.flex
{
    import flash.display.DisplayObject;

    import mx.core.UIComponent;

    import org.flexthinker.binding.ui.form.binding.Binder;
    import org.flexthinker.binding.ui.form.binding.BinderFactory;

    import spark.components.RichEditableText;

    import spark.components.supportClasses.ListBase;
    import spark.components.supportClasses.Range;
    import spark.components.supportClasses.SkinnableTextBase;
    import spark.components.supportClasses.TextBase;
    import spark.components.supportClasses.ToggleButtonBase;

    /**
     * Creates a <code>Binder</code> for a given UI component.
     *
     * <p>
     *     This implementation emphasis only Flex 4.x components.
     *     Flex 3 components, mx ones, are not recognized.
     *     </p>
     */
    public class DefaultFlexBinderFactory implements BinderFactory
    {
        /**
         * Constructor
         */
        public function DefaultFlexBinderFactory()
        {
        }

        /**
         * Returns a default <code>Binder</code> for a given component.
         *
         * @param component
         * @param formProperty
         * @return
         */
        public function getBinder(component:DisplayObject, formProperty:String):Binder
        {
            if (component is SkinnableTextBase || component is TextBase || component is RichEditableText)
            {
                //TextArea, TextInput, Label and RichText, RichEditableText
                return new TextBinder(UIComponent(component), formProperty);
            }

            if (component is ListBase)
            {
                // ButtonBar, ComboBox, DropDownList, List and TabBar
                return new ListBinder(ListBase(component), formProperty);
            }

            if (component is Range)
            {
                // HScrollBar, HSlider, NummericStepper, ScrollBarBase,ScrubBar, SliderBase, Spinner, TrackBase,
                // VscrollBar, VSlider, VolumeBar,
                return new RangeBinder(Range(component), formProperty);
            }
            if (component is ToggleButtonBase)
            {
                // CheckBox, RadioButton, ToggleButton
                return new ToggleButtonBaseBinder(ToggleButtonBase(component), formProperty);
            }


            return null;
        }
    }
}
